﻿using System;
using System.Data;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ProjectManApi.Extensions;
using Microsoft.AspNetCore.Authorization;
using Nacos.AspNetCore;
using learun.util;
using BusinessEntity.HT;
using BusinessEntity.HTGLQueery;
using BusinessEntity.HTGLQuerry;
using BusinessEntity;
using BusinessRule;
using NLog;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Net;
using System.Text;
using System.IO;
using System.Dynamic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Newtonsoft.Json.Linq;
using BusinessRepository;
using BusinessEntity.Warning;
using Microsoft.AspNetCore.Http;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Diagnostics;

namespace ProjectManApi.Controllers
{
    public class HTController : MvcControllerBase
    {
        #region "测试"

        private readonly INacosServerManager _serverManager;
        public HTController(INacosServerManager serverManager) : base(serverManager)
        {
            _serverManager = serverManager;
        }
        #endregion
        #region "合同字段设置"

        /// <summary>
        /// 获取合同字段设置信息
        /// </summary>
        /// <param name="htlxbh">合同类型编号</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ColShow(string htlxbh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.Contract.GetHT_ColShow(htlxbh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_ColShow([FromBody] HT_ColShow hT)
        {
            try
            {
                await BusinessRule.Contract.UpdateHT_ColShow(hT);
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion
        #region "合同类型管理"
        /// <summary>
        /// 获取合同类型
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_HTLX([FromQuery] HT_HTLXQuerry entity)
        {
            try
            {
                entity.UserID = GetUserId();
                (DataTable, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_HTLX(entity);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_HTLX([FromBody] HT_HTLX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_HTLX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_HTLX([FromBody] HT_HTLX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_HTLX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_HTLX([FromBody] HT_HTLX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_HTLX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> StopHT_HTLX([FromBody] HT_HTLX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.StopHT_HTLX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> StatrHT_HTLX([FromBody] HT_HTLX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.StartHT_HTLX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "付款合同管理"
        /// <summary>
        /// 获取付款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> GetHT_FKHTGL([FromQuery] HT_FKHTGLQuerry entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_FKHTGL(entity);

                //_logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

                //这里修改下
                Dictionary<string, List<string>> MyType = new Dictionary<string, List<string>>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string formcode = item.formcode;
                    string id = item.id;
                    //string htbh = item.htbh;

                    if (MyType.ContainsKey(formcode))
                    {
                        MyType[formcode].Add(id);
                    }
                    else
                    {
                        MyType.Add(formcode, new List<string>() { id });
                    }
                }

                //记下日志

                //_logger.Log(LogLevel.Info, "22222" + MyType.ToJson());


                List<JavaApi.SPSDataItem> spitems = new List<JavaApi.SPSDataItem>();
                foreach (var item in MyType)
                {
                    spitems = spitems.Union((await JavaApi.GetSPStatusJavaAPI(item.Key, GetUserAccount(), item.Value, await GetICApiInfo())).AsEnumerable<JavaApi.SPSDataItem>()).ToList();
                }

                //_logger.Log(LogLevel.Info, "33333" + spitems.ToJson());

                //List<string> list = new List<string>();
                //foreach (dynamic item in SelectTable.Item1)
                //{
                //    string id = item.htbh;
                //    list.Add(id);
                //}

                //List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {

                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }

                    item.panguData = GetPanGudData(spstatus, status);

                    //item.panguData = GetPanGudData(spstatus, status);
                }



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }


        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_FKHTXX(string htbh, string htmc, string htlx, string zt)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_FKHTXX(htbh, htmc, htlx, zt);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        //删除
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_FKHT([FromBody] HT_FKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_FKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        //作废
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> StopHT_FKHT([FromBody] HT_FKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.StopHT_FKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        //提交
        [HttpPost]
        //  [AllowAnonymous]
        public async Task<IActionResult> SubmitHT_FKHT([FromBody] HT_FKHT ht)
        {

            try
            {
                HT_SubmitHT htsubmit = new HT_SubmitHT();
                //    htsubmit.businessNo = ht.fkhtxx.htbh;
                //    htsubmit.amount = ht.fkhtxx.htje.ToString();
                //    htsubmit.deptName = ht.fkhtxx.sqbm;
                //    htsubmit.content = ht.fkhtxx.htmc;
                //  await JavaApi.UploadFileJavaAPI(ht.fkhtxx.htbh, ht.File, await GetICApiInfo());
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = ht.fkhtxx.htlx;
                spl.businessId = ht.fkhtxx.htbh;
                // spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.fkhtxx.htbh, amount = ht.fkhtxx.htje?.ToString(), content = ht.fkhtxx.htmc, deptName = ht.fkhtxx.sqbm };
                // spl.description = Newtonsoft.Json.JsonConvert.SerializeObject(htsubmit);
                spl.description = _description.ToJson();
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateStatus";
                spl.callbackInterface = "";
                if (ht.fkhtxx.htlx == "采购合同")
                {
                    spl.callbackInterface = "/contract-rule/payment/purchase-audit/audit/${taskId}/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htmc + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.zt + " ";

                }
                if (ht.fkhtxx.htlx == "通用付款合同")
                {
                    spl.callbackInterface = "/contract-rule/payment/currency-audit/audit/${taskId}/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htmc + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.zt + " ";

                }

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());


                //string url = BaseEditPower.GetSPDetailUrl(BaseEditPower.TableName.合同.ToString(), ht.fkhtxx.htbh);
                // JavaApi.SPLEnt spl = new JavaApi.SPLEnt("FKHTsubmit", ht.fkhtxx.htbh, ht.File.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx), "http://ic-xmzc/netapi/HT/SubmitHT_FKHT");
                //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (!bsp)
                {
                    await BusinessRule.HTGL.HT_HTGL.UpdateHT_HTZT(ht.fkhtxx.htbh, ht.fkhtxx.htlx, "1");
                    return Fail("提交失败，启动工作流异常");
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.SubmitHT_FKHT(ht.fkhtxx);

                    return Success("成功");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        //审核
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> AuditHT_FKHT([FromBody] HT_FKHT ht)
        {
            try
            {
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = "FKHTAudit";
                spl.businessId = ht.fkhtxx.htbh;
                //spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                //spl.description = ht.fkhtxx.htbh;
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/AuditHT_FKHT";

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (!bsp)
                {
                    return Fail("提交失败，启动工作流异常");
                }

                await BusinessRule.HTGL.HT_HTGL.AuditHT_FKHT(ht.fkhtxx);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        //驳回
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> BackHT_FKHT([FromBody] HT_FKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.BackHT_FKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 采购合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        //  [AllowAnonymous]
        public async Task<IActionResult> InsertHT_CGHT(HT_CGHT_Total ht)
        {

            try
            {


                if (await JavaApi.UploadFileJavaAPI(ht.cght.htbh, ht.fileCodes, await GetICApiInfo()))
                {

                    await BusinessRule.HTGL.HT_HTGL.InsertHT_CGHT(ht);

                }
                else
                {

                    await BusinessRule.HTGL.HT_HTGL.InsertHT_CGHT(ht);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_CGHT([FromBody] HT_CGHT ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_CGHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 项目合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_XMHT(HT_XMHT_Total ht)
        {
            string status = ht.xmht.zt;
            if (status == "2")
            {
                try
                {


                    //  await JavaApi.UploadFileJavaAPI(ht.fkhtxx.htbh, ht.File, await GetICApiInfo());
                    bool bsp = false;
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "项目合同";
                    spl.businessId = ht.xmht.htbh;
                    // spl.publicParamKey = "FEE_PROCESS";
                    spl.formCode = ht.fileCodes.code;

                    //spl.description = ht.fkhtxx.htbh;
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.xmht);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateStatus";


                    bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());


                    // string url = BaseEditPower.GetSPDetailUrl(BaseEditPower.TableName.合同.ToString(), ht.fkhtxx.htbh);
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("FKHTsubmit", ht.fkhtxx.htbh, ht.File.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx), "http://ic-xmzc/netapi/HT/SubmitHT_FKHT");
                    //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    if (!bsp)
                    {
                        return Fail("提交失败，启动工作流异常");
                    }
                    await BusinessRule.HTGL.HT_HTGL.SubmitHT(ht.xmht.htbh, "项目合同");

                    return Success("成功");
                }
                catch (Exception ex)
                {
                    return Fail(ex.Message);
                }
            }
            else
            {
                try
                {
                    if (await JavaApi.UploadFileJavaAPI(ht.xmht.htbh, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.InsertHT_XMHT(ht);
                    }

                    return Success("成功");
                }
                catch (Exception ex)
                {
                    return Fail(ex.Message);
                }
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_XMHT([FromBody] HT_XMHT ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_XMHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        /// <summary>
        /// 通用付款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_TYFKHT(HT_TYFKHT_Total ht)
        {

            try
            {
                if (await JavaApi.UploadFileJavaAPI(ht.tyfkht.htbh, ht.fileCodes, await GetICApiInfo()))
                {
                    //bool bsp = false;
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    //spl.businessName = "tyfkht";
                    //spl.businessId = ht.tyfkht.htbh;
                    ////spl.publicParamKey = "FEE_PROCESS";
                    //spl.formCode = ht.fileCodes.code;

                    //spl.description = ht.tyfkht.htbh;
                    //spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.tyfkht);
                    //spl.callbackUrl = "http://ic-xmzc/netapi/HT/InsertHT_TYFKHT";
                    ////
                    //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (bsp)
                    //{
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYFKHT(ht);
                    //}
                    //else
                    //{
                    //    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYFKHT(ht);
                    //}
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYFKHT(ht);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_TYFKHT([FromBody] HT_TYFKHT ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_TYFKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion
        #region "收款合同管理"
        /// <summary>
        /// 获取收款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> GetHT_SKHTGL([FromQuery] HT_SKHTGLQuerry entity)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKHTGL(entity);
                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.htbh;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.htbh;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unknown";
                    }


                    item.panguData = GetPanGudData(spstatus, status);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }


        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_SKHTXX(string htbh, string htlx)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKHTXX(htbh, htlx);
                //  DataTable SelectTable1 = await BusinessRule.HTGL.HT_HTGL.GetHT_HTZXBM(htbh);

                //  string json = Success(SelectTable).ToJson();


                return Success(SelectTable);
                // Success(SelectTable1);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_SKHT([FromBody] HT_SKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_SKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> StopHT_SKHT([FromBody] HT_SKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.StopHT_SKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> SubmitHT_SKHT([FromBody] HT_SKHT ht)
        {

            try
            {
                //HT_SubmitHT htsmbmit = new HT_SubmitHT();
                //htsmbmit.businessNo = ht.skhtxx.htbh;
                //htsmbmit.amount = ht.skhtxx.htje.ToString();
                //htsmbmit.deptName = ht.skhtxx.sqbm;
                //htsmbmit.content = ht.skhtxx.htmc;
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = ht.skhtxx.htlx;
                spl.businessId = ht.skhtxx.htbh;
                // spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                //spl.description = Newtonsoft.Json.JsonConvert.SerializeObject(htsmbmit);
                JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.skhtxx.htbh, amount = ht.skhtxx.htje?.ToString(), content = ht.skhtxx.htmc, deptName = ht.skhtxx.sqbm };
                spl.description = _description.ToJson();
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.skhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateStatus";
                spl.callbackInterface = "";
                if (ht.skhtxx.htlx == "租赁合同" && ht.File.code == "contract_collection2")
                {
                    spl.callbackInterface = "/contract2-rule/collection/lease-audit/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + " ";

                }
                else if (ht.skhtxx.htlx == "租赁合同")
                {
                    spl.callbackInterface = "/contract-rule/collection/lease-audit/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + " ";

                }
                else if (ht.skhtxx.htlx == "通用收款合同")
                {
                    spl.callbackInterface = "/contract-rule/collection/currency-audit/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + " ";

                }
                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (bsp)
                {
                    await BusinessRule.HTGL.HT_HTGL.SubmitHT_SKHT(ht.skhtxx);
                    return Success("成功");
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.UpdateHT_HTZT(ht.skhtxx.htbh, ht.skhtxx.htlx, "1");
                    return Fail("提交失败，启动工作流异常");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> AuditHT_SKHT([FromBody] HT_SKHT ht)
        {
            try
            {
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = "SKHTAudit";
                spl.businessId = ht.skhtxx.htbh;
                //spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                //spl.description = ht.skhtxx.htbh;
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.skhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/AuditHT_SKHT";

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (bsp)
                {
                    await BusinessRule.HTGL.HT_HTGL.AuditHT_SKHT(ht.skhtxx);
                    return Success("成功");
                }
                else { return Fail("提交失败，启动工作流异常"); }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> BackHT_SKHT([FromBody] HT_SKHTXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.BackHT_SKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 租赁合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_ZLHT(HT_ZLHT_Total ht)
        {

            try
            {

                if (await JavaApi.UploadFileJavaAPI(ht.zlht.htbh, ht.fileCodes, await GetICApiInfo()))
                {

                    await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT(ht);

                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT(ht);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                if (ht.zlht.Listid == "")
                {
                    await BusinessRule.HTGL.HT_HTGL.DeleteHT_ZLHT(ht.zlht.htbh);
                }
                return Fail(ex.Message);
            }

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_ZLHT([FromBody] HT_ZLHT ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_ZLHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> UpdateContract(contract co)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.UpdateContract(co);
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail("失败" + ex.Message);
            }
        }

        /// <summary>
        /// 通用收款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_TYSKHT(HT_TYSKHT_Total ht)
        {

            try
            {
                if (await JavaApi.UploadFileJavaAPI(ht.tyskht.htbh, ht.fileCodes, await GetICApiInfo()))
                {
                    //bool bsp = false;
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    //spl.businessName = "tyskht";
                    //spl.businessId = ht.tyskht.htbh;
                    ////spl.publicParamKey = "FEE_PROCESS";
                    //spl.formCode = ht.fileCodes.code;

                    //spl.description = ht.tyskht.htbh;
                    //spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.tyskht);
                    //spl.callbackUrl = "http://ic-xmzc/netapi/HT/InsertHT_TYSKHT";
                    ////
                    //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (bsp)
                    //{
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYSKHT(ht);
                    //}
                    //else
                    //{
                    //    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYSKHT(ht);
                    //}
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYSKHT(ht);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_TYSKHT([FromBody] HT_TYSKHT ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_TYSKHT(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHTSRB(string htbh,string bgdh)
        {
            try
            {

                try
                {

                    dynamic dynamic = new ExpandoObject();

                    dynamic.srqrb = await BusinessRule.HTGL.HT_HTGL.getsrqrbx(htbh,bgdh);
                    dynamic.yys = await BusinessRule.HTGL.HT_HTGL.getyysx(htbh,bgdh);
                    return Success(dynamic);
                }
                catch (Exception ex)
                {
                    return Fail("查询数据失败");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion



        #region "乙方信息"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_YFXXmain(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_YFXX(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_YFXXmain(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_YFXX(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_YFXXmain([FromBody] HT_YFXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_YFXX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        #endregion
        #region "标的物信息"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BDWXX(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BDWXX(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_BDWXX(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_BDWXX(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_BDWXX([FromBody] HT_BDWXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_BDWXX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        #endregion
        #region "收款账号"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htbh"></param>
        ///  /// <param name="bgdh"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_SKZH(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKZH(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_SKZH(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_SKZH(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_SKZH([FromBody] HT_SKZH ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_SKZH(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_SKYH(string htid)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKYH(htid);
                if (SelectTable.Rows.Count == 0)
                {
                    SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKYHx(htid);
                }
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        #endregion
        #region "付款计划"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_KFJH(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_FKJH(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_FKJH(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_FKJH(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_FKJH([FromBody] HT_FKJH ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_FKJH(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        #endregion
        #region "保证金"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BZJ(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BZJ(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_BZJ(string htbh)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_BZJ(htbh);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_BZJ(HT_BZJ_Total ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_BZJ(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> SoloHT_BZJ(HT_BZJ ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.SoloHT_BZJ(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> BackHT_BZJ(HT_BZJ_BACK ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.BackHT_BZJ(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }





        #endregion
        #region "租赁合同基本信息"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ZLHT_JBXX(string htbh, string zt)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_ZLHT_JBXX(htbh, zt);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_ZLHT_JBXX(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_ZLHT_JBXX(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_ZLHT_JBXX([FromBody] HT_ZLHT_JBXX ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT_JBXX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        #endregion
        #region "收款计划"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htbh"></param>
        ///  /// <param name="bgdh"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_SKJH(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKJH(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }



        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_SKJH(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_SKJH(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_SKJH(HT_SKJH_Total ht)
        {
            try
            {
                string bmdm = "";
                await BusinessRule.HTGL.HT_HTGL.UpdateHT_SKJH(ht);
                //娄葑用
                if (ht.zt == "3")
                {
                    DataTable ds = await BusinessRule.Contract.Getbmdm("320571050");
                    if (ds.Rows.Count == 1)
                    {
                        bmdm = ds.Rows[0][0].ToString();

                        string DepartID = await getDescendantList(bmdm);

                        string ver = await BusinessRule.Contract.GetLFpermission(ht.htbh, DepartID);
                        if (ver == "是")
                        {


                            string _url = "http://121.224.115.168:8081/lf_zcgl/contract/plans";
                            //json参数
                            ds = await BusinessRule.HTGL.HT_HTGL.GetHT_SKJH(ht.htbh, "");
                            List<dynamic> lists = new List<dynamic>();
                            for (int i = 0; i < ds.Rows.Count; i++)
                            {
                                dynamic skjh = new ExpandoObject();
                                //  skjh.listid = ds.Rows[i][0].ToString();//
                                skjh.contractNo = ds.Rows[i][1].ToString();//
                                skjh.paymentMethod = ds.Rows[i][2].ToString();
                                skjh.termName = ds.Rows[i][3].ToString();
                                skjh.percent = ds.Rows[i][4].ToString();
                                skjh.amount = ds.Rows[i][5].ToString().ToDecimal(); //

                                skjh.date = ds.Rows[i][6].ToString().ToDate().Year == 1 ? DateTime.Now : ds.Rows[i][6].ToString().ToDate();
                                skjh.content = ds.Rows[i][7].ToString();
                                lists.Add(skjh);
                            }
                            var request = (HttpWebRequest)WebRequest.Create(_url);
                            request.Method = "POST";
                            request.ContentType = "application/json;charset=UTF-8";
                            string plan = lists.ToJson();
                            byte[] byteData = Encoding.UTF8.GetBytes(plan);

                            int length = byteData.Length;
                            request.ContentLength = length;
                            Stream writer = request.GetRequestStream();
                            writer.Write(byteData, 0, length);
                            writer.Close();
                            var response = (HttpWebResponse)request.GetResponse();
                            var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
                            //Console.WriteLine(responseString.ToString());
                            //Console.ReadLine();
                        }
                    }
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        #endregion
        #region "租赁合同保底租金"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ZLHT_BDZJ(string htbh, string bgdh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_ZLHT_BDZJ(htbh, bgdh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_ZLHT_BDZJ(string Listid)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_ZLHT_BDZJ(Listid);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_ZLHT_BDZJ([FromBody] HT_ZLHT_BDZJ ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT_BDZJ(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }



        #endregion

        #region "资产信息"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="htbh"></param>
        ///   <param name="bgdh"></param>
        ///    <param name="htlx"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ZCXX(string htbh, string bgdh, string htlx,string type)
        {
            try
            {
                _logger.Info(type);
                DataTable SelectTable = null;
                if (string.IsNullOrEmpty(type))
                {
                    type = "0";
                }
                if (type == "0")
                {
                    SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_ZCXX(htbh, bgdh, htlx);
                }
                else
                {
                    SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_ZCXXx(htbh, bgdh, htlx);
                }
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_ZCXX(string htbh)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_ZCXX(htbh);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_ZCXX(HT_ZCXX_Total ht)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_ZCXX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }




        #endregion
        #region"合同执行部门"

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_HTZXBM(string htbh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_HTZXBM(htbh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        #endregion

        #region "资产合同"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_Assets(HT_AssetsQuerry querry)
        {
            try
            {
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_Assets(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_Assets(HT_Assets ht)
        {
            try
            {
                await BusinessRule.Contract.InsertHT_Assets(ht);
                return Success("成功");
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_Assets(HT_Assets ht)
        {
            try
            {
                await BusinessRule.Contract.UpdateHT_Assets(ht);
                return Success("成功");
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_Assets(string Listid)
        {
            try
            {
                await BusinessRule.Contract.DeleteHT_Assets(Listid);
                return Success("成功");
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_AssetsByID(string Listid)
        {

            try
            {
                await BusinessRule.Contract.GetHT_AssetsByID(Listid);
                return Success("成功");
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }

        }

        #endregion


        #region "合同变更管理"

        //获取变更单
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> GetHT_BGD([FromQuery] HT_BGDQuerry entity)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "id")
                {
                    entity.SortString = "sqrq";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BGD(entity);
                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.bgdh;
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.bgdh;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }
                    item.panguData = GetPanGudData(spstatus, status);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BGDDetail(string bgdh, string htlx)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BGDDetail(bgdh, htlx);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        //采购变更
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_CGHT_BGD([FromBody] HT_CGHT_Total bgd)
        {
            try
            {
                if (await JavaApi.UploadFileJavaAPI(bgd.cght.bgdh, bgd.fileCodes, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_CGHT_BGD(bgd);
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_CGHT_BGD(bgd);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        //项目变更
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_XMHT_BGD([FromBody] HT_XMHT_BGD bgd)
        {
            try
            {
                if (await JavaApi.UploadFileJavaAPI(bgd.bgdh, bgd.fileCodes, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_XMHT_BGD(bgd);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        //通用付款合同变更
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_TYFKHT_BGD([FromBody] HT_TYFKHT_Total bgd)
        {
            try
            {
                if (await JavaApi.UploadFileJavaAPI(bgd.tyfkht.bgdh, bgd.fileCodes, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYFKHT_BGD(bgd);
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYFKHT_BGD(bgd);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        //租赁合同变更
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_ZLHT_BGD(HT_ZLHT_BGD_Total bgd)
        {
            try
            {
                if (await JavaApi.UploadFileJavaAPI(bgd.zlhtbgd.bgdh, bgd.fileCodes, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT_BGD(bgd);
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT_BGD(bgd);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        //通用收款合同变更
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_TYSKHT_BGD([FromBody] HT_TYSKHT_Total bgd)
        {
            try
            {
                if (await JavaApi.UploadFileJavaAPI(bgd.tyskht.bgdh, bgd.fileCodes, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYSKHT_BGD(bgd);
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_TYSKHT_BGD(bgd);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        //删除
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteHT_BGD(string htbh, string bgdh, string htlx)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.DeleteHT_BGD(htbh, bgdh, htlx);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> SubmitHT_FKHTBGD([FromBody] HT_FKHT ht)
        {

            try
            {
                //    HT_SubmitHT htsubmit = new HT_SubmitHT();
                //    htsubmit.businessNo = ht.fkhtxx.htbh;
                //    htsubmit.amount = ht.fkhtxx.htje.ToString();
                //    htsubmit.deptName = ht.fkhtxx.sqbm;
                //    htsubmit.content = ht.fkhtxx.htmc;
                //  await JavaApi.UploadFileJavaAPI(ht.fkhtxx.htbh, ht.File, await GetICApiInfo());
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = ht.fkhtxx.htlx;
                spl.businessId = ht.fkhtxx.bgdh;
                // spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.fkhtxx.bgdh, amount = ht.fkhtxx.htje?.ToString(), content = ht.fkhtxx.htmc, deptName = ht.fkhtxx.sqbm };
                // spl.description = Newtonsoft.Json.JsonConvert.SerializeObject(htsubmit);
                spl.description = _description.ToJson();
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateStatusBGD";
                spl.callbackInterface = "";
                spl.callbackView = "";
                if (ht.fkhtxx.htlx == "采购合同")
                {
                    spl.callbackInterface = "/contract-rule/purchase-change/audit/${taskId}/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htmc + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.zt + "/" + ht.fkhtxx.bgdh + "/change-audit";
                    spl.callbackView = "/contract-rule/purchase-change/view/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.bgdh + "/change-view";


                }
                if (ht.fkhtxx.htlx == "通用付款合同")
                {
                    spl.callbackInterface = "/contract-rule/currency-change/audit/${taskId}/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htmc + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.zt + "/" + ht.fkhtxx.bgdh + "/change-audit";
                    spl.callbackView = "/contract-rule/currency-change/view/" + ht.fkhtxx.htbh + "/" + ht.fkhtxx.htlx + "/" + ht.fkhtxx.bgdh + "/change-view";

                }

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());


                //string url = BaseEditPower.GetSPDetailUrl(BaseEditPower.TableName.合同.ToString(), ht.fkhtxx.htbh);
                // JavaApi.SPLEnt spl = new JavaApi.SPLEnt("FKHTsubmit", ht.fkhtxx.htbh, ht.File.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx), "http://ic-xmzc/netapi/HT/SubmitHT_FKHT");
                //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (!bsp)
                {
                    return Fail("提交失败，启动工作流异常");
                }
                else
                {

                    await BusinessRule.HTGL.HT_HTGL.SubmitHT_BGD(ht.fkhtxx.bgdh, ht.fkhtxx.htlx);

                    return Success("成功");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }




        }
        [HttpPost]
        //[AllowAnonymous]
        public async Task<IActionResult> SubmitHT_SKHTBGD([FromBody] HT_SKHT ht)
        {

            try
            {
                //    HT_SubmitHT htsubmit = new HT_SubmitHT();
                //    htsubmit.businessNo = ht.fkhtxx.htbh;
                //    htsubmit.amount = ht.fkhtxx.
                //    htje.ToString();
                //    htsubmit.deptName = ht.fkhtxx.sqbm;
                //    htsubmit.content = ht.fkhtxx.htmc;
                //  await JavaApi.UploadFileJavaAPI(ht.fkhtxx.htbh, ht.File, await GetICApiInfo());
                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = ht.skhtxx.htlx;
                spl.businessId = ht.skhtxx.bgdh;
                // spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.code;

                JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.skhtxx.bgdh, amount = ht.skhtxx.htje?.ToString(), content = ht.skhtxx.htmc, deptName = ht.skhtxx.sqbm };
                // spl.description = Newtonsoft.Json.JsonConvert.SerializeObject(htsubmit);
                spl.description = _description.ToJson();
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.skhtxx);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateStatusBGD";
                spl.callbackInterface = "";
                if (ht.skhtxx.htlx == "租赁合同")
                {
                    if (ht.File.formCode == "contract_change")
                    {
                        spl.callbackInterface = "/contract-rule/lease/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + "/" + ht.skhtxx.bgdh + "/change-audit";
                        spl.callbackView = "/contract-rule/lease/view/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.bgdh + "/change-view";
                    }
                    else
                    {
                        spl.callbackInterface = "/contract2-rule/lease/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + "/" + ht.skhtxx.bgdh + "/change-audit";
                        spl.callbackView = "/contract2-rule/lease/view/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.bgdh + "/change-view";
                    }
                }
                if (ht.skhtxx.htlx == "通用收款款合同")
                {
                    spl.callbackInterface = "/contract-rule/currency-audit/audit/${taskId}/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htmc + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.zt + "/" + ht.skhtxx.bgdh + "/change-audit";
                    spl.callbackView = "/contract-rule/currency-audit/view/" + ht.skhtxx.htbh + "/" + ht.skhtxx.htlx + "/" + ht.skhtxx.bgdh + "/change-view";
                }

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());


                //string url = BaseEditPower.GetSPDetailUrl(BaseEditPower.TableName.合同.ToString(), ht.fkhtxx.htbh);
                // JavaApi.SPLEnt spl = new JavaApi.SPLEnt("FKHTsubmit", ht.fkhtxx.htbh, ht.File.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(ht.fkhtxx), "http://ic-xmzc/netapi/HT/SubmitHT_FKHT");
                //bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (!bsp)
                {
                    return Fail("提交失败，启动工作流异常");
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.SubmitHT_BGD(ht.skhtxx.bgdh, ht.skhtxx.htlx);

                    return Success("成功");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }




        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> AuditHT_BGD([FromBody] HT_BGD bgd)
        {
            try
            {

                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = "bgd";
                spl.businessId = bgd.bgdxx.htbh;
                //spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = bgd.File.code;

                // spl.description = bgd.bgdxx.htbh;
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(bgd.bgdxx);
                spl.callbackUrl = "";

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (bsp)
                {
                    await BusinessRule.HTGL.HT_HTGL.AuditHT_BGD(bgd.bgdxx.htbh, bgd.bgdxx.bgdh, bgd.bgdxx.htlx);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> BackHT_BGD(string htbh, string bgdh, string htlx)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.BackHT_BGD(htbh, bgdh, htlx);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> StopHT_BGD(string htbh, string bgdh, string htlx)
        {
            try
            {

                await BusinessRule.HTGL.HT_HTGL.StopHT_BGD(htbh, bgdh, htlx);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region"合同验收"


        //获取验收单
        [HttpGet]

        public async Task<IActionResult> GetHT_Accept([FromQuery] HT_AcceptQuerry entity)
        {
            try
            {
                entity.UserID = GetUserId();
                (DataTable, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_Accept(entity);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        //验收
        [HttpPost]

        public async Task<IActionResult> AcceptHT_YS(HT_Accept ht)
        {
            try
            {
                bool isadd = true;

                if (string.IsNullOrEmpty(ht.acceptht.listid))
                {
                    ht.acceptht.listid = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                }
                else
                {
                    isadd = false;
                }
                if (await JavaApi.UploadFileJavaAPI(ht.acceptht.listid, ht.File, await GetICApiInfo()))
                {
                    await BusinessRule.HTGL.HT_HTGL.AcceptHT_YS(ht, isadd);
                }


                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]

        public async Task<IActionResult> GetHT_YS([FromQuery] HT_AcceptQuerry entity)
        {
            try
            {
                entity.UserID = GetUserId();
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_YSD(entity);
                List<string> list = new List<string>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.listid.ToString();
                    list.Add(id);
                }

                List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {
                    string id = item.listid.ToString();
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unknown";
                    }


                    item.panguData = GetPanGudData(spstatus, status);
                }

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        //验收
        [HttpPost]

        public async Task<IActionResult> SubmitHT_YS(HT_Accept ht)
        {
            try
            {
                if (string.IsNullOrEmpty(ht.acceptht.zt))
                {
                    ht.acceptht.zt = "2";
                }
                if (string.IsNullOrEmpty(ht.acceptht.htbh))
                {
                    return Fail("请选择合同！");
                }
                decimal d = 0;
                foreach (HT_AcceptBDWXX bdw in ht.acceptbdwxx)
                {
                    d = d + Convert.ToDecimal(bdw.bcysje);
                }
                //if (Convert.ToDecimal(ht.acceptht.ysje).ToString("N2") != d.ToString("N2"))
                //{
                //    return Fail("本次验收金额");
                //}
                bool isadd = true;
                if (string.IsNullOrEmpty(ht.acceptht.listid))
                {

                    ht.acceptht.listid = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                }
                else
                {
                    isadd = false;
                }
                DataTable cght = await BusinessRule.HTGL.HT_HTGL.GetHT_CGHTByListidx(ht.acceptht.listid);
                _logger.Info("执行到这里cght");
                DataTable bdwxx = await BusinessRule.HTGL.HT_HTGL.GetHT_BDWXXByListidx(ht.acceptht.listid);
                _logger.Info("执行到这里bdwxx");
                decimal yysjr = 0;
                decimal zj = 0;
                if (cght.Rows.Count > 0)
                {
                    _logger.Info("执行到这里cght  ccc");
                    yysjr = Convert.ToDecimal(cght.Rows[0]["yysje"]);
                }
                if (bdwxx.Rows.Count > 0)
                {
                    _logger.Info("执行到这里bdwxx ccc" + bdwxx.Rows.Count);
                    zj = Convert.ToDecimal(bdwxx.Rows[0]["zj"]);
                }
                if (zj > 0 && zj < yysjr)
                {
                    _logger.Info("zj:" + zj + "yysjr:" + yysjr);
                    return Fail("提交验收金额超出待验收总额，请核实！");
                }
                if (await JavaApi.UploadFileJavaAPI(ht.acceptht.listid, ht.File, await GetICApiInfo()))
                {
                    _logger.Info("执行到这里");
                    ht.acceptht.listid = await BusinessRule.HTGL.HT_HTGL.AcceptHT_YS(ht, isadd);
                }

                bool bsp = false;
                JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                spl.businessName = "合同验收";
                spl.businessId = ht.acceptht.listid.ToString();
                // spl.publicParamKey = "FEE_PROCESS";
                spl.formCode = ht.File.formCode;

                //spl.description = Newtonsoft.Json.JsonConvert.SerializeObject(htsmbmit);
                JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.acceptht.listid.ToString(), amount = "", content = "合同验收", deptName = GetUserDeptName() };
                spl.description = _description.ToJson();
                spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.acceptht);
                spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateYSDStatus";
                spl.callbackInterface = "/procure/acceptance/audit/" + ht.acceptht.listid + "/:taskId";
                spl.callbackView = "procure/acceptance/view/" + ht.acceptht.listid;

                bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                if (bsp)
                {
                    if (await JavaApi.UploadFileJavaAPI(ht.acceptht.htbh, ht.File, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.SaveHT_YS(ht);
                    }
                    return Success("成功");
                }
                else
                {
                    //await BusinessRule.HTGL.HT_HTGL.UpdateHT_HTZT(ht.skhtxx.htbh, ht.skhtxx.htlx, "1");
                    return Fail("提交失败，启动工作流异常");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]

        public async Task<IActionResult> DeleteHT_YS(string listid)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.DeleteHT_YS(listid);
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpGet]
        public async Task<IActionResult> GetHT_YSDByListid(string listid)
        {
            try
            {
                dynamic dy = new ExpandoObject();
                dy.ys = await BusinessRule.HTGL.HT_HTGL.GetHT_YSDByListid(listid);
                dy.ht = await BusinessRule.HTGL.HT_HTGL.GetHT_CGHTByListid(listid);
                dy.bdwxx = await BusinessRule.HTGL.HT_HTGL.GetHT_BDWXXByListid(listid);
                dy.ysbd = await BusinessRule.HTGL.HT_HTGL.GetHT_BDWXX_YSByListid(listid);
                return Success(dy);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]

        public async Task<IActionResult> GetHT_AcceptJE(string htlx, string htbh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_AcceptJE(htlx, htbh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion


        #region"获取合同编号"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_GetHTBH(string htlx)
        {
            try
            {
                string htbh = "";
                if (htlx == "采购合同")
                {
                    htbh = await JavaApi.BusinessBMJavaAPI("contract_payment_cght", htlx, await GetICApiInfo());

                }
                if (htlx == "项目合同")
                {
                    htbh = await JavaApi.BusinessBMJavaAPI("contract_payment_xmht", htlx, await GetICApiInfo());

                }
                if (htlx == "通用付款合同")
                {
                    htbh = await JavaApi.BusinessBMJavaAPI("contract_payment_fkht", htlx, await GetICApiInfo());

                }
                if (htlx == "租赁合同")
                {
                    htbh = await JavaApi.BusinessBMJavaAPI("contract_collection_zlht", htlx, await GetICApiInfo());

                }
                if (htlx == "通用收款合同")
                {
                    htbh = await JavaApi.BusinessBMJavaAPI("contract_collection_skht", htlx, await GetICApiInfo());

                }
                //  DataTable SelectTable = await BusinessRule.Contract.GetHT_GetHTBH(htlx);
                return Success(htbh);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        #endregion


        #region "下拉框弹窗"

        // 甲方
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_JFXX(string jfmc)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_JFXX(jfmc);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        // 乙方
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_YFXX(string yfmc)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_YFXX(yfmc);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        // 丙方
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BFXX(string bfmc)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BFXX(bfmc);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        // SKZH
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_SKZHDetail(string gys)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKZHXX(gys);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }


        #endregion

        #region"获取合同列表   支付 收款"

        //获取付款合同列表
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_List([FromQuery] HT_List entity)
        {
            try
            {
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_List(entity);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }


        //获取收款合同列表
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_skList([FromQuery] HT_List querry)
        {
            try
            {
                querry.UserID = GetUserId();
                querry.DepartID = await GetDepId("contract_permission");
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_skList(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> GetSKHT(JObject htbh)
        {
            try
            {
                string hts = "";
                foreach (string h in htbh["htbh"])
                {
                    hts += "'" + h + "',";
                }
                hts = hts.Substring(0, hts.LastIndexOf(","));
                DataTable SelectTable = await BusinessRule.Contract.GetskList(hts);

                return Success(SelectTable);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> Insert_SKXX([FromBody] HT_SKXXx ht)
        {
            try
            {
                if (string.IsNullOrEmpty(ht.listid))
                { 
                ht.listid= DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                }
                await BusinessRule.HTGL.HT_HTGL.InsertHT_SKXX(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> Insert_SKXXList([FromBody] List<HT_SKXXx> ht)
        {
            try
            {
                foreach (HT_SKXXx sk in ht)
                {
                    if (string.IsNullOrEmpty(sk.listid))
                    {
                        sk.listid = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                    }
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_SKXX(sk);
                }

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion
        #region"获取合同执行情况"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_Order([FromQuery] HT_Order querry)
        {
            try
            {
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_Order(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_OrderList([FromQuery] HT_List querry)
        {
            try
            {
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_OrderList(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }
        #endregion

        #region"获取变更合同列表及记录"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ListBGD([FromQuery] HT_List querry)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                querry.UserID = GetUserId();
                querry.DepartID = await GetDepId("contract_permission");
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_ListBGD(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BGDrecord(string htbh, string htlx)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.Contract.GetHT_BGDrecord(htbh, htlx);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        #endregion


        #region"获取保证金列表"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BZJList([FromQuery] HT_List querry)
        {
            try
            {
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_BZJ(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }



        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BZJone(string listid)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.Contract.GetHT_BZJone(listid);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        #endregion

        #region 审批流回调状态

        //合同回调
        [HttpPost]
        public async Task<IActionResult> UpdateStatus(dynamic spjson)//
        {

            //module，dealUser，approveStatus，businessName，businessId
            try
            {
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    return Fail("业务id不能为空");
                }

                //待提交  未审核  审核中  作废  已审核  驳回
                //DRAFT  UNCHECK, CHECKING,INVALID,CHECKED
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);

                _logger.Info("合同编号:" + businessId + "合同类型：" + businessName + "状态：" + zt);

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_HTZT(businessId, businessName, zt);
                //娄葑用
                if (zt == "3")
                {
                    if (businessName == "租赁合同" || businessName == "通用收款合同")
                    {
                        string bmdm = "";

                        DataTable ds = await BusinessRule.Contract.Getbmdm("320571050");
                        if (ds.Rows.Count == 1)
                        {
                            bmdm = ds.Rows[0][0].ToString();

                            string DepartID = await getDescendantList(bmdm);

                            string ver = await BusinessRule.Contract.GetLFpermission(businessId, DepartID);
                            if (ver == "是")
                            {


                                string _url = "http://121.224.115.168:8081/lf_zcgl/contract/plans";
                                //json参数
                                ds = await BusinessRule.HTGL.HT_HTGL.GetHT_SKJH(businessId, "");
                                List<dynamic> lists = new List<dynamic>();
                                for (int i = 0; i < ds.Rows.Count; i++)
                                {
                                    dynamic skjh = new ExpandoObject();
                                    //skjh.listid = ds.Rows[i][0].ToString();//
                                    skjh.contractNo = ds.Rows[i][1].ToString();//
                                    skjh.paymentMethod = ds.Rows[i][2].ToString();
                                    skjh.termName = ds.Rows[i][3].ToString();
                                    skjh.percent = ds.Rows[i][4].ToString();
                                    skjh.amount = ds.Rows[i][5].ToString().ToDecimal(); //

                                    skjh.date = ds.Rows[i][6].ToString().ToDate().Year == 1 ? DateTime.Now : ds.Rows[i][6].ToString().ToDate();
                                    skjh.content = ds.Rows[i][7].ToString();
                                    lists.Add(skjh);
                                }
                                var request = (HttpWebRequest)WebRequest.Create(_url);
                                request.Method = "POST";
                                request.ContentType = "application/json;charset=UTF-8";
                                byte[] byteData = Encoding.UTF8.GetBytes(lists.ToJson());
                                int length = byteData.Length;
                                request.ContentLength = length;
                                Stream writer = request.GetRequestStream();
                                writer.Write(byteData, 0, length);
                                writer.Close();
                                var response = (HttpWebResponse)request.GetResponse();
                                var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
                                //MessageBox.Show(responseString.ToString());
                            }

                        }
                    }
                }
                //if (operation == "RESTART")//消审以后
                //{
                //    ztz = "-1";//未提交的状态
                //}

                //  string strTname = businessName;

                //if (await BaseEditPower.GetEditPowerOpe(businessId, strTname, ztz))
                //{

                //}
                //else
                //{
                //    return Fail("请确认当前数据权限状态");
                //}

                // await BaseEditPower.SetStatus(businessId, strTname, ztz, GetUserName(), userid, CommonHelper.ParseDecimal(sdje));

                #region 加日志
                LogEntity logEntity = new LogEntity();
                logEntity.F_CategoryId = 3;
                logEntity.F_OperateTypeId = ((int)OperationType.Audit).ToString();
                logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Audit);
                logEntity.F_OperateAccount = ContextHelper.GetItem("userName") as string;
                logEntity.F_OperateUserId = ContextHelper.GetItem("userId") as string;
                logEntity.F_Module = Request.Path;
                logEntity.F_IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                logEntity.F_ExecuteResult = -1;
                var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
                logEntity.F_ExecuteResultJson = JsonConvert.SerializeObject(spjson, timeConverter);
                //添加日志
                await LogRule.Write(logEntity);
                #endregion


                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }

        //变更单回调
        [HttpPost]
        public async Task<IActionResult> UpdateStatusBGD(dynamic spjson)//
        {

            //module，dealUser，approveStatus，businessName，businessId
            try
            {
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    return Fail("业务id不能为空");
                }

                //待提交  未审核  审核中  作废  已审核  驳回
                //DRAFT  UNCHECK, CHECKING,INVALID,CHECKED
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
               
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);

                // if(zt=="3"||zt=="5")

                await BusinessRule.HTGL.HT_HTGL.UpdateHT_BGDZT(businessId, businessName, zt);


                //if (operation == "RESTART")//消审以后
                //{
                //    ztz = "-1";//未提交的状态
                //}

                //  string strTname = businessName;

                //if (await BaseEditPower.GetEditPowerOpe(businessId, strTname, ztz))
                //{

                //}
                //else
                //{
                //    return Fail("请确认当前数据权限状态");
                //}

                // await BaseEditPower.SetStatus(businessId, strTname, ztz, GetUserName(), userid, CommonHelper.ParseDecimal(sdje));

                #region 加日志
                LogEntity logEntity = new LogEntity();
                logEntity.F_CategoryId = 3;
                logEntity.F_OperateTypeId = ((int)OperationType.Audit).ToString();
                logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Audit);
                logEntity.F_OperateAccount = ContextHelper.GetItem("userName") as string;
                logEntity.F_OperateUserId = ContextHelper.GetItem("userId") as string;
                logEntity.F_Module = Request.Path;
                logEntity.F_IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                logEntity.F_ExecuteResult = -1;
                var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
                logEntity.F_ExecuteResultJson = JsonConvert.SerializeObject(spjson, timeConverter);
                //添加日志
                await LogRule.Write(logEntity);
                #endregion


                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> UpdateYSDStatus(dynamic spjson)//
        {

            //module，dealUser，approveStatus，businessName，businessId
            try
            {
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    return Fail("业务id不能为空");
                }

                //待提交  未审核  审核中  作废  已审核  驳回
                //DRAFT  UNCHECK, CHECKING,INVALID,CHECKED
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);



                await BusinessRule.HTGL.HT_HTGL.UpdateHT_YSStatus(businessId, zt);
                //娄葑用
                if (zt == "3")
                {
                    if (businessName == "租赁合同" || businessName == "通用收款合同")
                    {
                        string bmdm = "";

                        DataTable ds = await BusinessRule.Contract.Getbmdm("320571050");
                        if (ds.Rows.Count == 1)
                        {
                            bmdm = ds.Rows[0][0].ToString();

                            string DepartID = await getDescendantList(bmdm);

                            string ver = await BusinessRule.Contract.GetLFpermission(businessId, DepartID);
                            if (ver == "是")
                            {


                                string _url = "http://121.224.115.168:8081/lf_zcgl/contract/plans";
                                //json参数
                                ds = await BusinessRule.HTGL.HT_HTGL.GetHT_SKJH(businessId, "");
                                List<dynamic> lists = new List<dynamic>();
                                for (int i = 0; i < ds.Rows.Count; i++)
                                {
                                    dynamic skjh = new ExpandoObject();
                                    //skjh.listid = ds.Rows[i][0].ToString();//
                                    skjh.contractNo = ds.Rows[i][1].ToString();//
                                    skjh.paymentMethod = ds.Rows[i][2].ToString();
                                    skjh.termName = ds.Rows[i][3].ToString();
                                    skjh.percent = ds.Rows[i][4].ToString();
                                    skjh.amount = ds.Rows[i][5].ToString().ToDecimal(); //

                                    skjh.date = ds.Rows[i][6].ToString().ToDate().Year == 1 ? DateTime.Now : ds.Rows[i][6].ToString().ToDate();
                                    skjh.content = ds.Rows[i][7].ToString();
                                    lists.Add(skjh);
                                }
                                var request = (HttpWebRequest)WebRequest.Create(_url);
                                request.Method = "POST";
                                request.ContentType = "application/json;charset=UTF-8";
                                byte[] byteData = Encoding.UTF8.GetBytes(lists.ToJson());
                                int length = byteData.Length;
                                request.ContentLength = length;
                                Stream writer = request.GetRequestStream();
                                writer.Write(byteData, 0, length);
                                writer.Close();
                                var response = (HttpWebResponse)request.GetResponse();
                                var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
                                //MessageBox.Show(responseString.ToString());
                            }

                        }
                    }
                }
                //if (operation == "RESTART")//消审以后
                //{
                //    ztz = "-1";//未提交的状态
                //}

                //  string strTname = businessName;

                //if (await BaseEditPower.GetEditPowerOpe(businessId, strTname, ztz))
                //{

                //}
                //else
                //{
                //    return Fail("请确认当前数据权限状态");
                //}

                // await BaseEditPower.SetStatus(businessId, strTname, ztz, GetUserName(), userid, CommonHelper.ParseDecimal(sdje));

                #region 加日志
                LogEntity logEntity = new LogEntity();
                logEntity.F_CategoryId = 3;
                logEntity.F_OperateTypeId = ((int)OperationType.Audit).ToString();
                logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Audit);
                logEntity.F_OperateAccount = ContextHelper.GetItem("userName") as string;
                logEntity.F_OperateUserId = ContextHelper.GetItem("userId") as string;
                logEntity.F_Module = Request.Path;
                logEntity.F_IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                logEntity.F_ExecuteResult = -1;
                var timeConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
                logEntity.F_ExecuteResultJson = JsonConvert.SerializeObject(spjson, timeConverter);
                //添加日志
                await LogRule.Write(logEntity);
                #endregion


                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }
        #endregion


        #region "产交合同/娄葑租赁合同附件"
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xmbh"></param>

        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_ContractFile(string xmbh)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_ContractFile(xmbh);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }








        #endregion

        #region"金华钉钉合同"

        //获取付款合同列表
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_DDHT([FromQuery] HT_List querry)
        {
            try
            {
                (DataTable, int) SelectTable = await BusinessRule.Contract.GetHT_DDHT(querry);
                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                return Success(pa);
            }
            catch (Exception e)
            {
                return Fail(e.Message);
            }
        }

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> Insert_DDHT([FromBody] HT_DDHT ht)
        {
            try
            {
                //  string ht = json;
                //  List<HT_DDHT> ht= json.ToList<HT_DDHT>();

                //List<HT_DDHT> ht= (List<HT_DDHT>)IJsonHelper.jsonDes < List < HT_DDHT >>(json);
                string htbh = await JavaApi.BusinessBMJavaAPI("contract_payment_fkht", "通用付款合同", await GetICApiInfo());
                //  string htbh = "123456";
                await BusinessRule.Contract.InsertHT_DDHT(ht, htbh);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion



        #region"娄葑租赁合同"
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> InsertHT_ZLHT_LF(HT_ZLHT_Total ht)
        {

            try
            {
                string ver = await BusinessRule.Contract.GetLFCJHT(ht.zlht.xmbh);
                if (ver == "是")
                {
                    await BusinessRule.HTGL.HT_HTGL.InsertHT_ZLHT_LF(ht);
                }
                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        #endregion

        #region"测绘"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_BZJch(string Listid)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_BZJch(Listid);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_Detail(string keyStr, string type)
        {
            try
            {
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_Detail(keyStr, type);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        #endregion

        #region "产交权限"
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_PermissionCode([FromBody] HT_Permission ht)
        {
            try
            {

                await BusinessRule.Contract.UpdateHT_PermissionCode(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        #endregion

        #region"合同按钮权限"


        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> UpdateHT_Button([FromBody] HT_Button ht)
        {
            try
            {

                await BusinessRule.Contract.UpdateHT_Button(ht);

                return Success("成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }


        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetHT_Button()
        {
            try
            {
                DataTable SelectTable = await BusinessRule.Contract.GetHT_Button();
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }

        }
        #endregion


        #region "出租方信息"
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> GetCZFXX(string czfmc, string listid, string deptid)
        {
            try
            {
                if (string.IsNullOrEmpty(deptid))
                {
                    deptid = GetUserDeptid();
                }
                DataTable table = await BusinessRule.HTGL.HT_HTGL.GetCZFXX(czfmc, listid, deptid);
                return Success(table);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> SaveCZFXX(ht_czfxx xx)
        {
            try
            {
                if (string.IsNullOrEmpty(xx.listid))
                {
                    xx.listid = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                    await BusinessRule.HTGL.HT_HTGL.InsertCZFXX(xx);
                }
                else
                {
                    await BusinessRule.HTGL.HT_HTGL.UpdateCZFXX(xx);
                }
                return Success("保存成功！");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> DeleteCZFXX(string listid)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.DeleteCZFXX(listid);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        /// <summary>
        /// 下载导入模板
        /// </summary>
        /// <returns>文件流</returns>
        [HttpGet]
        [AllowAnonymous]
        public IActionResult Download()
        {

            try
            {
                string baseDir = ConfigHelper.GetValue<string>("baseDir");
                string filePath = baseDir + "/UpLoad/Template/出租人导入模板.xls";
                return File(FileHelper.Read(filePath), "application/ms-excel", "出租人导入模板.xls");
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
            //return response;
        }
        /// <summary>
        /// 导入
        /// </summary>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> Import([FromForm] IFormCollection formCollection)
        {
            try
            {
                string baseDir = ConfigHelper.GetValue<string>("baseDir");
                if (formCollection.Files.Count == 0)
                {
                    return Fail("请上传文件");
                }
                FormFileCollection filelist = (FormFileCollection)formCollection.Files;

                string nfilepath = "";
                string newfilename = "";
                foreach (IFormFile file in filelist)
                {
                    String Tpath = "/UpLoad/Files/";
                    string name = file.FileName;
                    string FileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    string FilePath = baseDir + Tpath;

                    string type1 = Path.GetExtension(name);
                    DirectoryInfo di = new DirectoryInfo(FilePath);

                    if (!di.Exists)
                    {
                        di.Create();
                    }

                    using (FileStream fs = System.IO.File.Create(FilePath + FileName + type1))
                    {
                        // 复制文件
                        file.CopyTo(fs);
                        // 清空缓冲区数据
                        fs.Flush();
                    }
                    nfilepath = FilePath + FileName + type1;
                    newfilename = FileName + type1;

                }

                DataTable ds = ExcelHelper.ExcelImport(nfilepath);

                List<ht_czfxx> list = new List<ht_czfxx>();
                int indext = 1;
                foreach (DataRow row in ds.Rows)
                {
                    ht_czfxx ht = new ht_czfxx();
                    ht.listid = DateTime.Now.ToString("yyyyMMddHHmmssffffff") + indext;
                    ht.czfmc = Convert.ToString(row[0]);
                    ht.xydm = Convert.ToString(row[1]);
                    ht.fddz = Convert.ToString(row[2]);
                    ht.khh = Convert.ToString(row[3]);
                    ht.yhzh = Convert.ToString(row[4]);
                    ht.frdb = Convert.ToString(row[5]);
                    ht.zlyt = Convert.ToString(row[6]);
                    list.Add(ht);
                    await BusinessRule.HTGL.HT_HTGL.InsertCZFXX(ht);
                    indext++;
                }

                return Success(list);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "公建房"
        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getht_gjflist([FromQuery] ht_gjfCondition entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "ListID")
                {
                    entity.SortString = "id";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.getht_gjf(entity);

                _logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

                //这里修改下
                Dictionary<string, List<string>> MyType = new Dictionary<string, List<string>>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string formcode = entity.FormCode;
                    string id = item.id;
                    //string htbh = item.htbh;

                    if (MyType.ContainsKey(formcode))
                    {
                        MyType[formcode].Add(id);
                    }
                    else
                    {
                        MyType.Add(formcode, new List<string>() { id });
                    }
                }

                //记下日志

                //_logger.Log(LogLevel.Info, "22222" + MyType.ToJson());


                List<JavaApi.SPSDataItem> spitems = new List<JavaApi.SPSDataItem>();
                foreach (var item in MyType)
                {
                    spitems = spitems.Union((await JavaApi.GetSPStatusJavaAPI(item.Key, GetUserAccount(), item.Value, await GetICApiInfo())).AsEnumerable<JavaApi.SPSDataItem>()).ToList();
                }

                //_logger.Log(LogLevel.Info, "33333" + spitems.ToJson());

                //List<string> list = new List<string>();
                //foreach (dynamic item in SelectTable.Item1)
                //{
                //    string id = item.htbh;
                //    list.Add(id);
                //}

                //List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {

                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }

                    item.panguData = GetPanGudData(spstatus, status);

                    //item.panguData = GetPanGudData(spstatus, status);
                }



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 保存和提交
        /// </summary>
        /// <param name="gjf"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> saveGJF(ht_gjf_enter gjf)
        {
            try
            {
                if (string.IsNullOrEmpty(gjf.gjf.zcdm))
                {
                    var dwinfo = await GetDepInfoSig(gjf.gjf.ssdwdm, "project_permission");
                    _logger.Info("单位id：" + gjf.gjf.ssdwdm);
                    _logger.Info("单位信息：" + dwinfo.ToString());
                    string bname = gjf.gjf.dwdm;
                    if (null != dwinfo)
                    {
                        if (!string.IsNullOrEmpty(dwinfo.mnemonicCode))
                        {
                            bname = dwinfo.mnemonicCode;
                        }
                        else
                        {
                            bname = dwinfo.code;
                        }
                    }
                    else
                    {
                        _logger.Info("未取得单位信息，单位id：" + gjf.gjf.ssdwdm);
                    }
                    dynamic DCcode = new ExpandoObject();
                    DCcode.bmdm = bname;//部门代码
                    _logger.Info("单位id：" + bname);
                    _logger.Info("参数：" + Newtonsoft.Json.JsonConvert.SerializeObject(DCcode));
                    _logger.Info("参数x：" + Newtonsoft.Json.JsonConvert.SerializeObject(DCcode));
                    gjf.gjf.zcdm = await JavaApi.BusinessBMJavaAPI("contract_gjf", Newtonsoft.Json.JsonConvert.SerializeObject(DCcode), await GetICApiInfo());
                    _logger.Info("资产编码：" + gjf.gjf.zcdm);

                }

                if (gjf.action == "insert")
                {
                    gjf.gjf.id = DateTime.Now.ToString("yyyyMMddHHmmssfff");

                    gjf.gjf.zt = "1";
                    if (await JavaApi.UploadFileJavaAPI(gjf.gjf.id, gjf.FileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.insertht_gjf(gjf.gjf);

                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }

                }
                else if (gjf.action == "update")
                {
                    if (string.IsNullOrEmpty(gjf.gjf.zt))
                    {
                        gjf.gjf.zt = "1";
                    }
                    if (await JavaApi.UploadFileJavaAPI(gjf.gjf.id, gjf.FileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.updateht_gjf(gjf.gjf);

                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (gjf.action == "submit")
                {
                    if (string.IsNullOrEmpty(gjf.gjf.zcdm))
                    {
                        gjf.gjf.zcdm = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                    }
                    if (string.IsNullOrEmpty(gjf.gjf.zt))
                    {
                        gjf.gjf.zt = "1";
                    }

                    if (string.IsNullOrEmpty(gjf.gjf.id))
                    {
                        gjf.gjf.id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                        if (await JavaApi.UploadFileJavaAPI(gjf.gjf.id, gjf.FileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.insertht_gjf(gjf.gjf);
                        }
                    }
                    JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = gjf.gjf.id, amount = "", content = "公建房管理" + gjf.gjf.id, deptName = GetUserDeptName() };
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "公建房管理";
                    spl.businessId = gjf.gjf.id;
                    // spl.publicParamKey = "FEE_PROCESS";
                    spl.formCode = gjf.FileCodes.formCode;
                    spl.description = _description.ToJson();
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(gjf.gjf);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/Updateht_gjfStatus";
                    spl.callbackInterface = "/contract-rule/publicly-owned/${taskId}/" + gjf.gjf.id + "/audit";
                    spl.callbackView = "/contract-rule/publicly-owned/" + gjf.gjf.id + "/view";
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("资产发布",id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(str), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                    //bool bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (!bsp)
                    string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                    _logger.Log(LogLevel.Info, "审批流调用结束");
                    //ht.spl = strInstanceId;
                    if (strInstanceId.StartsWith("err"))
                    {
                        if (await JavaApi.UploadFileJavaAPI(gjf.gjf.id, gjf.FileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.updateht_gjf(gjf.gjf);
                        }
                        return Fail("提交失败，启动工作流异常");
                    }
                    else
                    {
                        if (await JavaApi.UploadFileJavaAPI(gjf.gjf.id, gjf.FileCodes, await GetICApiInfo()))
                        {

                            gjf.gjf.zt = "2";


                            await BusinessRule.HTGL.HT_HTGL.updateht_gjf(gjf.gjf);
                        }
                        return Success("提交成功");
                    }
                }
                else
                {
                    return Fail("action参数不合法");
                }
            }
            catch (Exception e)
            {
                if (gjf.action == "insert")
                {
                    await BusinessRule.HTGL.HT_HTGL.deleteht_gjf(gjf.gjf.id);
                }
                return Fail("失败" + e.Message);
            }
        }

        [HttpPost]
        //[AllowAnonymous]
        //[HttpPost]
        public async Task<IActionResult> Updateht_gjfStatus(dynamic spjson)
        {
            //module，dealUser，approveStatus，businessName，businessId
            //dynamic spjson
            try
            {
                //_logger.Info(spjson.ToString());
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    //return Fail("业务id不能为空");
                    return Json(new ResParameter { code = ResponseCode.fail, message = "业务id不能为空" });
                }

                //待提交，未审核，审核中 ，作废 ，已审核 ，驳回 ，撤销
                //DRAFT，UNCHECK, CHECKING,INVALID,CHECKED,RESTART
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);


                _logger.Info("状态" + zt);
                await BusinessRule.HTGL.HT_HTGL.Updategjfstatus(businessId, zt);
                _logger.Info("状态x" + zt);
                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                _logger.Info("状态y" + ex.Message);
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }
        /// <summary>
        /// 根据id删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> deleteht_gjf(string id)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.deleteht_gjf(id);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail("失败" + ex.Message);
            }


        }
        /// <summary>
        /// 根据编号查询数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> getht_gjf(string id)
        {
            try
            {
                DataTable dt = await BusinessRule.HTGL.HT_HTGL.getht_gjfentity(id);
                return Success(dt);
            }
            catch (Exception e)
            {
                return Fail("获取数据失败" + e.Message);
            }
        }
        #endregion
        #region "产交合同变更"
        [HttpPost]
        public async Task<IActionResult> SaveContract_BGD(EnterContract enter)
        {
            try
            {
                if (string.IsNullOrEmpty(enter.ht.bgdh))
                {
                    enter.ht.bgdh = await JavaApi.BusinessBMJavaAPI("contract_change", "", await GetICApiInfo());
                }
                if (string.IsNullOrEmpty(enter.ht.zt))
                {
                    enter.ht.zt = "1";
                }
                if (enter.action == "insert")
                {
                    if (await JavaApi.UploadFileJavaAPI(enter.ht.bgdh, enter.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.InsertContract_BGD(enter);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (enter.action == "update")
                {
                    if (await JavaApi.UploadFileJavaAPI(enter.ht.bgdh, enter.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.InsertContract_BGD(enter);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (enter.action == "submit")
                {

                    //if (await JavaApi.UploadFileJavaAPI(enter.ht.bgdh, enter.fileCodes, await GetICApiInfo()))
                    //{
                    //    await BusinessRule.HTGL.HT_HTGL.InsertContract_BGD(enter);
                    //}

                    JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = enter.ht.bgdh, amount = "", content = "产交合同变更" + enter.ht.bgdh, deptName = GetUserDeptName() };
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "合同变更";
                    spl.businessId = enter.ht.bgdh;
                    // spl.publicParamKey = "FEE_PROCESS";
                    spl.formCode = enter.fileCodes.formCode;
                    spl.description = _description.ToJson();
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(enter.ht);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateContractStatus";
                    if (enter.ht.sssqbm.Contains("320571050"))
                    {
                        spl.callbackInterface = "/contract-rule/lease-cjbg-lou-feng/audit/${taskId}/" + enter.ht.contractcode + "/" + enter.ht.contractname + "/产交合同/" + enter.ht.zt + "/" + enter.ht.bgdh + "/change-audit";
                    }
                    else
                    {
                        spl.callbackInterface = "/contract-rule/lease-cjbg/audit/${taskId}/" + enter.ht.contractcode + "/" + enter.ht.contractname + "/产交合同/" + enter.ht.zt + "/" + enter.ht.bgdh + "/change-audit";
                    }
                    spl.callbackView = "/contract-rule/lease-cjbg-lou-feng/view/" + enter.ht.contractcode + "/" + enter.ht.contractname + "/产交合同/" + enter.ht.zt + "/" + enter.ht.bgdh + "/change-view";
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("资产发布",id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(str), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                    //bool bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (!bsp)
                    string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                    _logger.Log(LogLevel.Info, "审批流调用结束");
                    //ht.spl = strInstanceId;
                    if (strInstanceId.StartsWith("err"))
                    {
                        if (await JavaApi.UploadFileJavaAPI(enter.ht.bgdh, enter.fileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.InsertContract_BGD(enter);
                        }
                        return Fail("提交失败，启动工作流异常");
                    }
                    else
                    {
                       // enter.fileCodes.needToValid = "true";
                        if (await JavaApi.UploadFileJavaAPI(enter.ht.bgdh, enter.fileCodes, await GetICApiInfo()))
                        {
                            enter.ht.zt = "2";
                            await BusinessRule.HTGL.HT_HTGL.InsertContract_BGD(enter);
                        }
                        return Success("提交成功");
                    }
                }
                else
                {
                    return Fail("action参数不存在");
                }

            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> DeleteContract_BGD(string id)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.deleteContract_BGD(id);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail("删除失败");
            }
        }
        [HttpGet]
        public async Task<IActionResult> GetContract_BGD(string bgdh)
        {
            try
            {
                //DataTable dataTable = await BusinessRule.HTGL.HT_HTGL.getcontract_bgd(bgdh);
                //Contract_BGD ht = new Contract_BGD();
                //ht = APICommond.DataToEntity.DataTableToEntity<Contract_BGD>(dataTable);
                dynamic dynamic = new ExpandoObject();
                dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getcontract_bgdx(bgdh);
                dynamic.skjh = await BusinessRule.HTGL.HT_HTGL.getcontractPlan_bgd(bgdh);
                dynamic.zcxx = await BusinessRule.HTGL.HT_HTGL.getAssets_bgd(bgdh);
                dynamic.bzj = await BusinessRule.HTGL.HT_HTGL.getBzj_bgd(bgdh);
                dynamic.srqrb = await BusinessRule.HTGL.HT_HTGL.getsrqrb_bgd(bgdh);
                dynamic.yys = await BusinessRule.HTGL.HT_HTGL.getyys_bgd(bgdh);
                return Success(dynamic);
            }
            catch (Exception ex)
            {
                return Fail("查询数据失败");
            }
        }

        [HttpPost]
        public async Task<IActionResult> UpdateContractStatus(dynamic spjson)
        {
            try
            {
                //_logger.Info(spjson.ToString());
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    //return Fail("业务id不能为空");
                    return Json(new ResParameter { code = ResponseCode.fail, message = "业务id不能为空" });
                }

                //待提交，未审核，审核中 ，作废 ，已审核 ，驳回 ，撤销
                //DRAFT，UNCHECK, CHECKING,INVALID,CHECKED,RESTART
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);


                _logger.Info("状态" + zt);
                await BusinessRule.HTGL.HT_HTGL.UpdateContractStatus(businessId, zt);
                _logger.Info("状态x" + zt);
                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                _logger.Info("状态y" + ex.Message);
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }

        }

        [HttpGet]
        public async Task<IActionResult> GetContract(string htbh)
        {
            try
            {

                dynamic dynamic = new ExpandoObject();
                dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getcontract(htbh);
                dynamic.skjh = await BusinessRule.HTGL.HT_HTGL.getcontractPlan(htbh);
                dynamic.zcxx = await BusinessRule.HTGL.HT_HTGL.getAssets(htbh);
                dynamic.bzj = await BusinessRule.HTGL.HT_HTGL.getBzj(htbh);
                dynamic.srqrb = await BusinessRule.HTGL.HT_HTGL.getsrqrb(htbh);
                dynamic.yys = await BusinessRule.HTGL.HT_HTGL.getyys(htbh);
                return Success(dynamic);
            }
            catch (Exception ex)
            {
                return Fail("查询数据失败");
            }
        }
        #endregion


        #region "合同报表"
        [HttpGet]
        public async Task<IActionResult> getcontractassets([FromQuery] assetquerry querry)
        {
            try
            {
                (DataTable, int) select = await BusinessRule.HTGL.HT_HTGL.getcontractassets(querry);

                //DataTable dt= select.Item1;
                //int c = Convert.ToInt32(querry.month);

                Page pa = new Page();
                pa.records = select.Item1;
                pa.total = select.Item2;
                return Success(pa);
                //DataTable dt= await BusinessRule.HTGL.HT_HTGL.getcontractassetsx(querry);
                //return Success(dt);
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<FileResult> exprotContractAssets([FromQuery] assetquerry querry)
        {

            DataTable dt = await BusinessRule.HTGL.HT_HTGL.getcontractassetsx(querry);
            string filestring = APICommond.ExptExcel.createContractAssets(dt);
            _logger.Info("生成文件内容成功");
            string filePath = AppContext.BaseDirectory + "DownLoad\\";
            if (!System.IO.Directory.Exists(filePath))
            {
                System.IO.Directory.CreateDirectory(filePath);
            }
            filePath = AppContext.BaseDirectory + "DownLoad\\合同导出.xls";
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }

            FileStream st = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);


            byte[] d = Encoding.UTF8.GetBytes(filestring);

            st.Write(d, 0, d.Length);
            st.Close();
            st.Dispose();
            _logger.Info("写入文件成功");
            FileStream stream = new FileStream(filePath, FileMode.Open);

            var actionresult = new FileStreamResult(stream, new Microsoft.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream"));
            actionresult.FileDownloadName = "合同导出.xls";
            _logger.Info("文件已准备好下载");
            return actionresult;

        }


        /// <summary>
        /// 获取欠缴情况分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getReportQJ([FromQuery] reportQj entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "Listid")
                {
                    entity.SortString = "djbh";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetQJ(entity);

                _logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

               


                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "合同终止"
        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getht_zzhtlist([FromQuery] ht_zzhtQuerry entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "ListID")
                {
                    entity.SortString = "id";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.getht_htzzList(entity);

                _logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

                //这里修改下
                Dictionary<string, List<string>> MyType = new Dictionary<string, List<string>>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string formcode = entity.FormCode;
                    string id = item.id;
                    //string htbh = item.htbh;

                    if (MyType.ContainsKey(formcode))
                    {
                        MyType[formcode].Add(id);
                    }
                    else
                    {
                        MyType.Add(formcode, new List<string>() { id });
                    }
                }

                //记下日志

                //_logger.Log(LogLevel.Info, "22222" + MyType.ToJson());


                List<JavaApi.SPSDataItem> spitems = new List<JavaApi.SPSDataItem>();
                foreach (var item in MyType)
                {
                    spitems = spitems.Union((await JavaApi.GetSPStatusJavaAPI(item.Key, GetUserAccount(), item.Value, await GetICApiInfo())).AsEnumerable<JavaApi.SPSDataItem>()).ToList();
                }

                //_logger.Log(LogLevel.Info, "33333" + spitems.ToJson());

                //List<string> list = new List<string>();
                //foreach (dynamic item in SelectTable.Item1)
                //{
                //    string id = item.htbh;
                //    list.Add(id);
                //}

                //List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {

                    string id = item.id;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }

                    item.panguData = GetPanGudData(spstatus, status);

                    //item.panguData = GetPanGudData(spstatus, status);
                }



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> gethtlist([FromQuery] ht_zzhtQuerry entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "ListID")
                {
                    entity.SortString = "htbh";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.getht_htList(entity);





                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> SaveHT_ZZHT(Enterht_zzht ht)
        {
            try
            {
                if (string.IsNullOrEmpty(ht.ht.zt))
                {
                    ht.ht.zt = "1";
                }
                if (string.IsNullOrEmpty(ht.ht.id))
                {
                    ht.ht.id = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                }
                if (ht.action == "insert")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.ht.id, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.Insertht_zzht(ht.ht);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "update")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.ht.id, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.deleteht_zzht(ht.ht.id);
                        await BusinessRule.HTGL.HT_HTGL.Insertht_zzht(ht.ht);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "submit")
                {
                    JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.ht.id, amount = "", content = "合同终止" + ht.ht.id, deptName = GetUserDeptName() };
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "合同终止";
                    spl.businessId = ht.ht.id;
                    // spl.publicParamKey = "FEE_PROCESS";
                    spl.formCode = ht.fileCodes.formCode;
                    spl.description = _description.ToJson();
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.ht);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/UpdateHT_ZZHTStatus";
                    spl.callbackInterface = "/terminate/${taskId}/" + ht.ht.id + "/audit";
                    spl.callbackView = "/terminate/" + ht.ht.id + "/view";
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("资产发布",id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(str), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                    //bool bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (!bsp)
                    string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                    _logger.Log(LogLevel.Info, "审批流调用结束");
                    //ht.spl = strInstanceId;
                    if (strInstanceId.StartsWith("err"))
                    {
                        if (await JavaApi.UploadFileJavaAPI(ht.ht.id, ht.fileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.deleteht_zzht(ht.ht.id);
                            await BusinessRule.HTGL.HT_HTGL.Insertht_zzht(ht.ht);
                        }
                        return Fail("提交失败，启动工作流异常");
                    }
                    else
                    {
                        ht.fileCodes.needToValid = "true";
                        if (await JavaApi.UploadFileJavaAPI(ht.ht.id, ht.fileCodes, await GetICApiInfo()))
                        {

                            ht.ht.zt = "2";
                            await BusinessRule.HTGL.HT_HTGL.deleteht_zzht(ht.ht.id);
                            await BusinessRule.HTGL.HT_HTGL.Insertht_zzht(ht.ht);
                        }
                        return Success("提交成功");
                    }
                }
                else
                {
                    return Fail("action参数不合规");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        //[AllowAnonymous]
        //[HttpPost]
        public async Task<IActionResult> UpdateHT_ZZHTStatus(dynamic spjson)
        {
            //module，dealUser，approveStatus，businessName，businessId
            //dynamic spjson
            try
            {
                //_logger.Info(spjson.ToString());
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    //return Fail("业务id不能为空");
                    return Json(new ResParameter { code = ResponseCode.fail, message = "业务id不能为空" });
                }

                //待提交，未审核，审核中 ，作废 ，已审核 ，驳回 ，撤销
                //DRAFT，UNCHECK, CHECKING,INVALID,CHECKED,RESTART
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);


                _logger.Info("状态" + zt);
                await BusinessRule.HTGL.HT_HTGL.Updateghtzzstatus(businessId, zt);
                _logger.Info("状态x" + zt);
                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                _logger.Info("状态y" + ex.Message);
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }

        /// <summary>
        /// 根据id删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> deleteht_zzht(string id)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.deleteht_zzht(id);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail("失败" + ex.Message);
            }


        }
        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> getht_zzht(string id)
        {
            try
            {

                try
                {

                    dynamic dynamic = new ExpandoObject();

                    dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getht_zzht(id);
                    dynamic.xzht = await BusinessRule.HTGL.HT_HTGL.getht_htBYhtbh(id);
                    return Success(dynamic);
                }
                catch (Exception ex)
                {
                    return Fail("查询数据失败");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> getht_zzhtx(string htbh)
        {
            try
            {

                try
                {

                    dynamic dynamic = new ExpandoObject();

                    dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getht_zzhtx(htbh);
                   
                    return Success(dynamic);
                }
                catch (Exception ex)
                {
                    return Fail("查询数据失败");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "收款计划"
        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getContractPlan(string htbh,string listid)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.getContractPlan(htbh,listid);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 获取收款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> getCollectionContract([FromQuery] HT_SKHTGLQuerry entity)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                entity.zt = "3";
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKHTGL(entity);

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }


        [HttpPost]
       
        public async Task<IActionResult> getCollectionContractx([FromBody] string[] htbh)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
               
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.GetHT_SKHTGLx(htbh);

                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 获取收款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> getInvoice(string htbh)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
              
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.getinvoice(htbh);

            
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "欠缴情况"

        /// <summary>
        /// 获取欠缴情况分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getht_qjlist([FromQuery] ht_qjQuerry entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
               
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.getht_qjList(entity);

               // _logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

                //这里修改下
                Dictionary<string, List<string>> MyType = new Dictionary<string, List<string>>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string formcode = entity.FormCode;
                    string id = item.listid;
                    //string htbh = item.htbh;

                    if (MyType.ContainsKey(formcode))
                    {
                        MyType[formcode].Add(id);
                    }
                    else
                    {
                        MyType.Add(formcode, new List<string>() { id });
                    }
                }

                //记下日志

                //_logger.Log(LogLevel.Info, "22222" + MyType.ToJson());


                List<JavaApi.SPSDataItem> spitems = new List<JavaApi.SPSDataItem>();
                foreach (var item in MyType)
                {
                    spitems = spitems.Union((await JavaApi.GetSPStatusJavaAPI(item.Key, GetUserAccount(), item.Value, await GetICApiInfo())).AsEnumerable<JavaApi.SPSDataItem>()).ToList();
                }

               // _logger.Log(LogLevel.Info, "33333" + spitems.ToJson());

                //List<string> list = new List<string>();
                //foreach (dynamic item in SelectTable.Item1)
                //{
                //    string id = item.htbh;
                //    list.Add(id);
                //}

                //List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {

                    string id = item.listid;
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }

                    item.panguData = GetPanGudData(spstatus, status);

                    //item.panguData = GetPanGudData(spstatus, status);
                }



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> SaveHT_qj(enterht_qj ht)
        {
            try
            {
                if (string.IsNullOrEmpty(ht.qj.zt))
                {
                    ht.qj.zt = "1";
                }
                if (string.IsNullOrEmpty(ht.qj.djbh))
                {
                    
                        ht.qj.djbh = await JavaApi.BusinessBMJavaAPI("contract_zj", "", await GetICApiInfo());
                    
                }
                if (ht.qj.djbh == "")
                {
                    ht.qj.djbh = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                }
                if (string.IsNullOrEmpty(ht.qj.listid))
                {
                    ht.qj.listid = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                }
                if (ht.action == "insert")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.qj.listid, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.insertht_qj(ht.qj);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "update")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.qj.listid, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.deleteht_qj(ht.qj.listid);
                        await BusinessRule.HTGL.HT_HTGL.insertht_qj(ht.qj);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "submit")
                {
                    JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.qj.listid, amount = "", content = "合同欠缴" + ht.qj.listid, deptName = GetUserDeptName() };
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "合同欠缴";
                    spl.businessId = ht.qj.listid;
                    // spl.publicParamKey = "FEE_PROCESS";
                    spl.formCode = ht.fileCodes.formCode;
                    spl.description = _description.ToJson();
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.qj);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/Updateht_qjStatus";
                    spl.callbackInterface = "/contract-rule/recovery-situation/${taskId}/" + ht.qj.listid+"/audit";
                    spl.callbackView = "/contract-rule/recovery-situation/"+ht.qj.listid+"/view 查看";
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("资产发布",id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(str), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                    //bool bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (!bsp)
                    string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                    _logger.Log(LogLevel.Info, "审批流调用结束");
                    //ht.spl = strInstanceId;
                    if (strInstanceId.StartsWith("err"))
                    {
                        if (await JavaApi.UploadFileJavaAPI(ht.qj.listid, ht.fileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.deleteht_qj(ht.qj.listid);
                            await BusinessRule.HTGL.HT_HTGL.insertht_qj(ht.qj);
                        }
                        return Fail("提交失败，启动工作流异常");
                    }
                    else
                    {
                        ht.fileCodes.needToValid = "true";
                        if (await JavaApi.UploadFileJavaAPI(ht.qj.listid, ht.fileCodes, await GetICApiInfo()))
                        {

                            ht.qj.zt = "2";
                            await BusinessRule.HTGL.HT_HTGL.deleteht_qj(ht.qj.listid);
                            await BusinessRule.HTGL.HT_HTGL.insertht_qj(ht.qj);
                        }
                        return Success("提交成功");
                    }
                }
                else
                {
                    return Fail("action参数不合规");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        //[AllowAnonymous]
        //[HttpPost]
        public async Task<IActionResult> Updateht_qjStatus(dynamic spjson)
        {
            //module，dealUser，approveStatus，businessName，businessId
            //dynamic spjson
            try
            {
                //_logger.Info(spjson.ToString());
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    //return Fail("业务id不能为空");
                    return Json(new ResParameter { code = ResponseCode.fail, message = "业务id不能为空" });
                }

                //待提交，未审核，审核中 ，作废 ，已审核 ，驳回 ，撤销
                //DRAFT，UNCHECK, CHECKING,INVALID,CHECKED,RESTART
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);


                _logger.Info("状态" + zt);
                await BusinessRule.HTGL.HT_HTGL.updateht_qj(zt,businessId);
                _logger.Info("状态x" + zt);
                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                _logger.Info("状态y" + ex.Message);
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }


        /// <summary>
        /// 根据id删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> deleteht_qj(string id)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.deleteht_qj(id);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail("失败" + ex.Message);
            }


        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> getht_qj(string id)
        {
            try
            {

                try
                {

                    dynamic dynamic = new ExpandoObject();

                    dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getht_skht(id);
                    dynamic.skjh = await BusinessRule.HTGL.HT_HTGL.getht_skjh(id);
                    dynamic.qj= await BusinessRule.HTGL.HT_HTGL.getht_qj(id);
                    return Success(dynamic);
                }
                catch (Exception ex)
                {
                    return Fail("查询数据失败");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getContractPlanList(string htbh, string listid)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.getContractPlanlist(htbh, listid);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }
        #endregion

        #region "合同收款"

        /// <summary>
        /// 获取欠缴情况分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> gethtsklist([FromQuery] skQuerry entity)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "ListID")
                {
                    entity.SortString = "listid";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.getht_skList(entity);

                _logger.Log(LogLevel.Info, "11111" + SelectTable.ToJson());

                //这里修改下
                Dictionary<string, List<string>> MyType = new Dictionary<string, List<string>>();
                foreach (dynamic item in SelectTable.Item1)
                {
                    string formcode = entity.FormCode;

                    //_logger.Log(LogLevel.Info, "11111x" + item.listID);
                    //_logger.Log(LogLevel.Info, "11111x" + item.listid);
                    string id = item.listid;
                    //string htbh = item.htbh;

                    if (MyType.ContainsKey(formcode))
                    {
                        MyType[formcode].Add(id);
                    }
                    else
                    {
                        MyType.Add(formcode, new List<string>() { id });
                    }
                }

                //记下日志

                //_logger.Log(LogLevel.Info, "22222" + MyType.ToJson());


                List<JavaApi.SPSDataItem> spitems = new List<JavaApi.SPSDataItem>();
                foreach (var item in MyType)
                {
                    spitems = spitems.Union((await JavaApi.GetSPStatusJavaAPI(item.Key, GetUserAccount(), item.Value, await GetICApiInfo())).AsEnumerable<JavaApi.SPSDataItem>()).ToList();
                }

                //_logger.Log(LogLevel.Info, "33333" + spitems.ToJson());

                //List<string> list = new List<string>();
                //foreach (dynamic item in SelectTable.Item1)
                //{
                //    string id = item.htbh;
                //    list.Add(id);
                //}

                //List<JavaApi.SPSDataItem> spitems = await JavaApi.GetSPStatusJavaAPI(entity.FormCode, GetUserAccount(), list, await GetICApiInfo());
                foreach (dynamic item in SelectTable.Item1)
                {

                    string id = item.listid;
                    //_logger.Log(LogLevel.Info, "33333" + id);
                    var spstatus = spitems.Where(ii => ii.businessId == id).FirstOrDefault();
                    //_logger.Log(LogLevel.Info, "33333" + spstatus.ToJson());
                    string status = "unknown";
                    if (item.zt == "1")
                    {
                        status = "draft";

                    }
                    else if (item.zt == "2")
                    {
                        status = "uncheck";

                    }
                    else if (item.zt == "9")
                    {
                        status = "checking";

                    }
                    else if (item.zt == "3")
                    {
                        status = "checked";

                    }
                    else if (item.zt == "4")
                    {
                        status = "reject";

                    }
                    else if (item.zt == "5")
                    {
                        status = "invalid";

                    }
                    else if (item.zt == "6")
                    {
                        status = "changing";

                    }
                    else if (item.zt == "7")
                    {
                        status = "bfys";

                    }
                    else if (item.zt == "8")
                    {
                        status = "yys";

                    }
                    else
                    {
                        status = "unfilled";
                    }

                    item.panguData = GetPanGudData(spstatus, status);

                    //item.panguData = GetPanGudData(spstatus, status);
                }



                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 获取收款合同
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>

        [HttpGet]
        //[AllowAnonymous]
        public async Task<IActionResult> getskhtx([FromQuery] HT_SKHTGLQuerry entity)
        {
            try
            {
                _logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                entity.UserID = GetUserId();
                entity.DepartID = await GetDepId("contract_permission");
                if (entity.SortString == "ListID")
                {
                    entity.SortString = "listid";
                }
                (IEnumerable<dynamic>, int) SelectTable = await BusinessRule.HTGL.HT_HTGL.Getskht(entity);

                Page pa = new Page();
                pa.records = SelectTable.Item1;
                pa.total = SelectTable.Item2;
                _logger.Log(LogLevel.Info, Success(pa).ToJson());
                return Success(pa);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }


        /// <summary>
        /// 获取公建房分页
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpGet]
        // [AllowAnonymous]
        public async Task<IActionResult> getContractPlanx(string htbh, string listid)
        {
            try
            {
                //_logger.Log(LogLevel.Info, this.Url.Action() + this.Request.QueryString.Value);
                DataTable SelectTable = await BusinessRule.HTGL.HT_HTGL.getContractPlanx(htbh, listid);
                return Success(SelectTable);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex.Message);
                return Fail(ex.Message);
            }
        }

        [HttpPost]
        public async Task<IActionResult> SaveHT_SK(enterSk ht)
        {
            try
            {
                if (string.IsNullOrEmpty(ht.sk.zt))
                {
                    ht.sk.zt = "1";
                }
                if (string.IsNullOrEmpty(ht.sk.djbh))
                {

                    ht.sk.djbh = await JavaApi.BusinessBMJavaAPI("contract_zj", "", await GetICApiInfo());

                }
                if (ht.sk.djbh == "")
                {
                    ht.sk.djbh= DateTime.Now.ToString("yyyyMMddHHmmssfff");
                }
                if (string.IsNullOrEmpty(ht.sk.listid))
                {
                    ht.sk.listid = DateTime.Now.ToString("yyyyMMddHHmmssfff");
                }
                if (ht.action == "insert")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.sk.listid, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.insertht_sk(ht.sk);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "update")
                {
                    ht.fileCodes.needToValid = "false";
                    if (await JavaApi.UploadFileJavaAPI(ht.sk.listid, ht.fileCodes, await GetICApiInfo()))
                    {
                        await BusinessRule.HTGL.HT_HTGL.deleteht_sk(ht.sk.listid);
                        await BusinessRule.HTGL.HT_HTGL.insertht_sk(ht.sk);
                        return Success("保存成功");
                    }
                    else
                    {
                        return Fail("处理上传文件时失败");
                    }
                }
                else if (ht.action == "submit")
                {
                    ht.fileCodes.needToValid = "true";
                    if (await JavaApi.UploadFileJavaAPI(ht.sk.listid, ht.fileCodes, await GetICApiInfo()))
                    {

                        ht.sk.zt = "1";
                        await BusinessRule.HTGL.HT_HTGL.deleteht_sk(ht.sk.listid);
                        await BusinessRule.HTGL.HT_HTGL.insertht_sk(ht.sk);
                    }

                    JavaApi.SPLEnt.Auditdescription _description = new JavaApi.SPLEnt.Auditdescription() { businessNo = ht.sk.listid, amount = "", content = "合同收款" + ht.sk.listid, deptName = GetUserDeptName() };
                    JavaApi.SPLEnt spl = new JavaApi.SPLEnt();
                    spl.businessName = "合同收款";
                    spl.businessId = ht.sk.listid;
                    // spl.publicParamKey = "FEE_PROCESS";

                    spl.formCode = ht.fileCodes.formCode;
                    spl.description = _description.ToJson();
                    spl.additionInfoJson = Newtonsoft.Json.JsonConvert.SerializeObject(ht.sk);
                    spl.callbackUrl = "http://ic-xmzc/netapi/HT/Updateht_skStatus";
                    spl.callbackInterface = "/contract-rule/contract-collection/${taskId}/" + ht.sk.listid + "/audit";
                    spl.callbackView = "/contract-rule/contract-collection/" + ht.sk.listid + "/view";
                    //JavaApi.SPLEnt spl = new JavaApi.SPLEnt("资产发布",id, filecodes.formCode, Newtonsoft.Json.JsonConvert.SerializeObject(str), "http://ic-xmzc/netapi/ProTZJH/UpdateStatus", url.Item1, url.Item2, _description);
                    //bool bsp = await JavaApi.startInstanceJavaAPI(spl, await GetICApiInfo());
                    //if (!bsp)
                    string strInstanceId = await JavaApi.startInstanceJavaAPIStr(spl, await GetICApiInfo());
                    _logger.Log(LogLevel.Info, "审批流调用结束");
                    //ht.spl = strInstanceId;
                    if (strInstanceId.StartsWith("err"))
                    {
                        if (await JavaApi.UploadFileJavaAPI(ht.sk.listid, ht.fileCodes, await GetICApiInfo()))
                        {
                            await BusinessRule.HTGL.HT_HTGL.deleteht_sk(ht.sk.listid);
                            await BusinessRule.HTGL.HT_HTGL.insertht_sk(ht.sk);
                        }
                        return Fail("提交失败，启动工作流异常");
                    }
                    else
                    {
                        ht.fileCodes.needToValid = "true";
                        if (await JavaApi.UploadFileJavaAPI(ht.sk.listid, ht.fileCodes, await GetICApiInfo()))
                        {

                            ht.sk.zt = "2";
                            await BusinessRule.HTGL.HT_HTGL.deleteht_sk(ht.sk.listid);
                            await BusinessRule.HTGL.HT_HTGL.insertht_sk(ht.sk);
                        }
                        return Success("提交成功");
                    }
                }
                else
                {
                    return Fail("action参数不合规");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }

        /// <summary>
        /// 根据id删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> deleteht_skx(string id)
        {
            try
            {
                await BusinessRule.HTGL.HT_HTGL.deleteht_sk(id);
                return Success("删除成功");
            }
            catch (Exception ex)
            {
                return Fail("失败" + ex.Message);
            }


        }

        [HttpPost]
        //[AllowAnonymous]
        //[HttpPost]
        public async Task<IActionResult> Updateht_skStatus(dynamic spjson)
        {
            //module，dealUser，approveStatus，businessName，businessId
            //dynamic spjson
            try
            {
                //_logger.Info(spjson.ToString());
                _logger.Debug(JsonConvert.SerializeObject(spjson));

                //{
                //    "businessId":"1403255058317729793",
                //    "businessName":"quotaDetailServiceImpl",
                //    "opinion":"合格，通过，批钱",
                //    "instanceId":352926,
                //    "taskId":352983
                //}
                //string taskId = spjson.taskId;
                //string businessName = spjson.businessName;
                //string instanceId = spjson.instanceId;

                string moduleid = spjson.module;
                string userid = spjson.dealUser;
                string approveStatus = spjson.approveStatus;//UNCHECK, CHECKING,REJECTED,INVALID,CHECKED

                //operation，值：AGREE（同意），REJECT（驳回），INVALID（作废），ACTIVATION（激活），CANCEL（撤销），RESTART（消审）
                string operation = spjson.operation;
                string businessId = spjson.businessId;
                string businessName = spjson.businessName;

                string additionInfo = spjson.additionInfo;

                //additionInfo： {
                //    sdje
                //    ywid
                //    tname
                //  }


                //这里加了一个审定金额



                if (string.IsNullOrEmpty(businessId))
                {
                    //return Fail("业务id不能为空");
                    return Json(new ResParameter { code = ResponseCode.fail, message = "业务id不能为空" });
                }

                //待提交，未审核，审核中 ，作废 ，已审核 ，驳回 ，撤销
                //DRAFT，UNCHECK, CHECKING,INVALID,CHECKED,RESTART
                string zt = "0";
                if (approveStatus == "DRAFT")
                {
                    zt = "1";
                }
                if (approveStatus == "UNCHECK")
                {
                    zt = "1";
                }
                if (approveStatus == "CHECKING")
                {
                    zt = "9";
                }
                if (approveStatus == "CHECKED")
                {
                    zt = "3";
                }
                if (approveStatus == "REJECT")
                {
                    zt = "4";
                }
                if (approveStatus == "INVALID")
                {
                    zt = "5";
                }
                if (approveStatus == "RESTART")
                {
                    zt = "1";
                }
                // string ztz = CProTZJHRule.GetXMGLSPZT(approveStatus);


                _logger.Info("状态" + zt);
                await BusinessRule.HTGL.HT_HTGL.updateht_sk(zt, businessId);
                _logger.Info("状态x" + zt);
                //return Success("操作成功");
                return Json(new ResParameter { code = ResponseCode.success, message = "成功" });
            }
            catch (Exception ex)
            {
                _logger.Info("状态y" + ex.Message);
                return Json(new ResParameter { code = ResponseCode.fail, message = "操作失败" + ex.Message });
                //return Fail("操作失败："+ ex.Message);
            }
        }

        [HttpGet]
        [AllowAnonymous]
        public async Task<IActionResult> getht_sk(string id)
        {
            try
            {

                try
                {

                    dynamic dynamic = new ExpandoObject();

                    dynamic.ht = await BusinessRule.HTGL.HT_HTGL.getht_skhtx(id);
                    dynamic.skjh = await BusinessRule.HTGL.HT_HTGL.getht_skjhx(id);
                    dynamic.qj = await BusinessRule.HTGL.HT_HTGL.getht_sk(id);
                    return Success(dynamic);
                }
                catch (Exception ex)
                {
                    return Fail("查询数据失败");
                }
            }
            catch (Exception ex)
            {
                return Fail(ex.Message);
            }
        }
        #endregion
    }
}
